package com.money.tracker.auth.service.impl;

import com.money.tracker.common.utils.LoginUtil;
import com.money.tracker.auth.entity.SysUser;
import com.money.tracker.auth.service.ISysMenuService;
import com.money.tracker.auth.service.ISysRoleService;
import com.money.tracker.auth.service.SysPermissionService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * <p>
 * 用户权限处理
 * <p>
 *
 * @author zhangshuai
 * &#064;@date 2024/09/28
 */
@Service
@RequiredArgsConstructor
public class SysPermissionServiceImpl implements SysPermissionService {

    private final ISysRoleService roleService;
    private final ISysMenuService menuService;

    @Override
    public Set<String> getRolePermission(SysUser user) {
        // 管理员拥有所有权限
        if (LoginUtil.isAdmin(user.getId())) {
            return Set.of("admin");
        }
        return roleService.getRolePermissionByUserId(user.getId());
    }

    @Override
    public Set<String> getMenuPermission(SysUser user) {
        // 管理员拥有所有权限
        if (LoginUtil.isAdmin()) {
            return Set.of("*:*:*");
        }
        return menuService.getMenuPermissionByUserId(user.getId());
    }
}
